﻿using System;
using System.Web;
using HtmlAgilityPack;

namespace Kwd.Summary.Services
{
  public class FirstParagraphSummary : ISummaryStrategy
  {
    public HtmlString GenerateSummary(HtmlString defaultSummary, Models.SummaryPart contentItem)
    {
      if (defaultSummary == null || String.IsNullOrWhiteSpace(defaultSummary.ToHtmlString()))
      { return new HtmlString(String.Empty); }

      var document = new HtmlDocument();
      document.LoadHtml(defaultSummary.ToHtmlString());
      var firstParagraph = document.DocumentNode.Element("p");
      
      return new HtmlString(firstParagraph.OuterHtml);
    }
  }
}